/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mybatis.model;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author ProjetGWTPhp
 */
public class TableModelTypeColumn extends AbstractTableModel {

    public static final int E_COLUMN_NAME_COL = 0;
    public static final int E_TYPE_COL = 1;
    public static final int E_ALIAS_COLUMN_COL = 2;
    public static final int E_PRIMARY_KEY_COL = 3;
    public String[] e_colNames = {
        "COLUMN NAME",
        "TYPE",
        "ALIAS COLUMN",
        "PRIMARY KEY",};
    public Class[] e_colTypes = {
        String.class,
        Object.class,
        String.class,
        Boolean.class
    };
    boolean[] canEdit = new boolean[]{
        false, true, true, true
    };
    List<BatisColumnTypeClass> eDataVector;

    public TableModelTypeColumn(List macDataVector) {
        super();

        eDataVector = macDataVector;
    }

    public void setRow(BatisColumnTypeClass batisCol) {
        this.eDataVector.add(batisCol);
        this.fireTableDataChanged();
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
    }

    @Override
    public int getColumnCount() {
        return e_colNames.length;
    }

    @Override
    public int getRowCount() {

        return eDataVector.size();
    }

    @Override
    public void setValueAt(Object value, int row, int col) {
        BatisColumnTypeClass eData =  eDataVector.get(row);
        switch (col) {
            case E_COLUMN_NAME_COL:
                eData.setCOLUMN_NAME((String) value);
                break;
            case E_TYPE_COL:
                eData.setTYPE(value);
                break;
            case E_ALIAS_COLUMN_COL:
                eData.setCOLUMN_ALIAS((String) value);
                break;
            case E_PRIMARY_KEY_COL:
                eData.setPRIMARY_KEY((Boolean) value);
                break;
        }
    }

    @Override
    public String getColumnName(int col) {
        return e_colNames[col];
    }

    @Override
    public Class getColumnClass(int col) {
        return e_colTypes[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        BatisColumnTypeClass eData =  eDataVector.get(row);

        switch (col) {
            case E_COLUMN_NAME_COL:
                return eData.getCOLUMN_NAME();
            case E_TYPE_COL:
                return eData.getTYPE();

            case E_ALIAS_COLUMN_COL:

                return eData.getCOLUMN_ALIAS();

            case E_PRIMARY_KEY_COL:

                return eData.getPRIMARY_KEY();
        }

        return new String();
    }
    public List<BatisColumnTypeClass> getRowAll(){
    return eDataVector;
    }
}